import axios from 'axios'

export default {
    namespaced: true,
    state: {
        top: {},
        about: {},
        self_introduction: "",
        avatar: "",
        we_chat: "",
    },
    actions: {
        // 我的信息
        getAbout: ({commit}) => {
            axios.get("/vue/about/index").then(response => {
                if (response.data.code === 0) {
                    commit('setTop', response.data.data.top || {});
                    commit('setAvatar', response.data.data.avatar || "");
                    commit('setSelfIntroduction', response.data.data.self_introduction || "");
                    commit('setAbout', response.data.data.about || {});
                }
            });
        },

        getWeChat: ({commit}) => {
            axios.get("/vue/about/we-chat").then(response => {
                if (response.data.code === 0) {
                    commit('setWeChat', response.data.data.image || "");
                }
            })
        }
    },
    mutations: {
        setTop(state, top) {
            state.top = top;
        },

        setAvatar(state, avatar) {
            state.avatar = avatar;
        },

        setSelfIntroduction(state, introduction) {
            state.self_introduction = introduction;
        },

        setAbout(state, about) {
            state.about = about;
        },

        setWeChat(state, image) {
            state.we_chat = image;
        }
    }
}